using PoemGame.Domain.Services.Factory.WebApi;
using PoemGame.Domain.Services;
using System.Data;
using Microsoft.Data.Sqlite;

var builder = WebApplication.CreateBuilder(args);
var services = builder.Services;
services.AddHttpClient();
services.AddScoped<IDomainServiceFactory<ICheckGameConditionService>, CheckGameConditionServiceFactory>();
services.AddScoped<IDomainServiceFactory<ICheckAnswerService>, CheckAnswerServiceFactory>();
services.AddScoped<IDbConnection, SqliteConnection>(serviceProvider => {
    var conn = new SqliteConnection();
    conn.ConnectionString = builder.Configuration.GetConnectionString("SqlitePoemConn");
    return conn;
});
services.AddControllers();

services.AddCors(option => option.AddPolicy("cors",
    policy => policy.AllowAnyHeader()
        .AllowAnyMethod()
        .AllowAnyOrigin()));

builder.Services.AddEndpointsApiExplorer();
builder.Services.AddSwaggerGen();

var app = builder.Build();

if (app.Environment.IsDevelopment())
{
    app.UseSwagger();
    app.UseSwaggerUI();
}

app.UseAuthorization();

app.MapControllers();
app.UseCors("cors");

app.Run();